<template>
	<view class="fui-wrap">
		<block v-if="is_admin">
			<fui-list>
				<fui-list-cell v-for="(item,index) in daili_list" arrow :key="index" @click="goDaili(item)">
					<view class="line">
						<fui-text :text="item.username" type="black" size="32" block fontWeight="bolder"></fui-text>
						<view style="margin-top: 20rpx;display: flex;justify-content: space-between;">
							<fui-text :text="`余额：${item.balance}`" type="black" size="28" block></fui-text>
							<fui-text :text="`停车场：${item.parking}`" type="black" size="28" block></fui-text>
						</view>
					</view>
				</fui-list-cell>
			</fui-list>
		</block>
		<block v-else>
			<view class="top" style="background:linear-gradient(to bottom, #43afe8, #fff);">
				<fui-avatar width="150" height="150" radius="30" :src="userinfo.avatar"></fui-avatar>
				<fui-text :text="userinfo.nickname" type="black" size="28"></fui-text>
				<fui-text :text="`余额：￥${balance}`" color="green" size="36"></fui-text>
			</view>
			<view class="err" v-if="!is_daili">
				 <fui-alert background="red" color="#fff" title="对不起，您不是代理商，如果您手里有停车场渠道资源，请联系我们，我们承诺共享收益!"></fui-alert>
			</view>
			<fui-grid :columns="2">
				<fui-grid-item @click="gourl('daili/park')">
					<view class="fui-grid__cell">
						<image :src="`${baseUrl}assets/img/miniapp/park.png`" class="fui-icon" mode="widthFix"></image>
						<fui-text text="我的停车场" type="black" size="28"></fui-text>
						<fui-text :text="`${parking}家`" color="green" size="28"></fui-text>
					</view>
				</fui-grid-item>
				<fui-grid-item>
					<view class="fui-grid__cell" @click="gourl('daili/log?type=0')">
						<image :src="`${baseUrl}assets/img/miniapp/stored.png`" class="fui-icon" mode="widthFix"></image>
						<fui-text text="收益记录" type="black" size="28"></fui-text>
						<fui-text :text="`合计：￥${heji}`" color="green" size="28"></fui-text>
					</view>
				</fui-grid-item>
				<fui-grid-item>
					<view class="fui-grid__cell" @click="gourl('daili/log?type=1')">
						<image :src="`${baseUrl}assets/img/miniapp/bill.png`" class="fui-icon" mode="widthFix"></image>
						<fui-text text="提现记录" type="black" size="28"></fui-text>
						<fui-text :text="`合计：￥${tixian}`" color="green" size="28"></fui-text>
					</view>
				</fui-grid-item>
				<fui-grid-item>
					<view class="fui-grid__cell" @click="ctixian">
						<image :src="`${baseUrl}assets/img/miniapp/entry.png`" class="fui-icon" mode="widthFix"></image>
						<fui-text text="发起提现" type="black" size="28"></fui-text>
					</view>
				</fui-grid-item>
			</fui-grid>
			<fui-modal :show="show" @click="onClick">
				<view class="fui-custom__wrap">
					<view class="panel">
						<view class="title">可提现：￥{{balance}}</view>
						<view class="input">
							<fui-input type="number" v-model="money" :inputBorder="true" borderColor="#c1c100"></fui-input>
						</view>
					</view>
				</view>
			</fui-modal>
		</block>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	export default {
		data() {
			return {
				baseUrl:baseUrl,
				userinfo:'',
				is_daili:0,
				is_admin:0,
				daili_list:[],
				parking:0,
				balance:0,
				heji:0,
				tixian:0,
				money:'',
				show:false
			}
		},
		onLoad() {
			this.login();
		},
		methods: {
			...methods,
			login:function(){
				this.$get('daili/login').then(res=>{
					let {userinfo,is_daili,is_admin,daili_list}=res;
					this.userinfo=userinfo;
					this.is_daili=is_daili;
					this.is_admin=is_admin;
					this.daili_list=daili_list;
					if(is_daili){
						this.getInfo();
					}
				});
			},
			goDaili:function(e){
				this.$get('daili/change',{id:e.id}).then(res=>{
					this.getInfo();
				});
			},
			getInfo:function(){
				this.$get('daili/info').then(res=>{
					let {parking,balance,heji,tixian}=res;
					this.parking=parking;
					this.balance=balance;
					this.heji=heji;
					this.tixian=tixian;
					this.is_admin=0;
					this.is_daili=1;
				});
			},
			gourl:function(e){
				if(!this.is_daili){
					this.$msg('对不起，您不是代理商');
					return;
				}
				this.$navigateTo(e);
			},
			onClick:function(e){
				if(e.index){
					if(this.money<100){
						this.$msg('每次提现金额至少100元');
						return;
					}
					this.$post('daili/tixian',{money:this.money},true,true).then(res=>{
						this.getInfo();
						this.show=false;
					});
				}else{
					this.show=false;
				}
			},
			ctixian:function(){
				if(!this.is_daili){
					this.$msg('对不起，您不是代理商');
					return;
				}
				this.money=this.balance;
				this.show=true;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.fui-wrap{
		background-color: #fff;
	}
	.line{
		width: 80%;
	}
	.parking{
		padding: 30rpx 0;
		text-align: center;
	}
	.err{
		padding: 20rpx;
		margin-bottom: 30rpx;
	}
	.top{
		background-color: #43afe8;
		display: flex;
		align-items: center;
		justify-content: space-around;
		flex-direction: column;
		height: 300rpx;
		padding: 100rpx 0 100rpx 0;
	}
	.fui-grid__cell{
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		text{
			margin-top: 10rpx;
		}
		.fui-icon{
			width: 120rpx;
			height: 120rpx;
		}
	}
	/* 自定义内容区样式需自行控制 */
	.fui-custom__wrap {
		width: 100%;
		height: 320rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		.panel{
			width: 90%;
			.title{
				font-size: 36rpx;
			}
			.input{
				margin-top: 20rpx;
			}
		}
	}
</style>